home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 49.6 KB | 1,667 lines | [TEXT/MPS ] |
- /*
- File: CappuccinoContent.cpp
-
- Contains: Class to encapsulate the content of the Cappuccino part.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- Cappuccino Includes --
-
- #ifndef _CAPPUCCINOCONTENT_
- #include "CappuccinoContent.h"
- #endif
-
- #ifndef _CAPPUCCINO_
- #include "Cappuccino.h"
- #endif
-
- #ifndef _CAPPUCCINOACTION_
- #include "CappuccinoAction.h"
- #endif
-
- #ifndef _CAPPUCCINODEF_
- #include "CappuccinoDef.h"
- #endif
-
- #ifndef _CAPPUCCINOGLOBALS_
- #include "CappuccinoGlobals.h"
- #endif
-
- #ifndef _CAPPUCCINOPROMISE_
- #include "CappuccinoPromise.h"
- #endif
-
- #ifndef _CAPPUCCINOUTILS_
- #include "CappuccinoUtils.h"
- #endif
-
- #ifndef _TEMPFOCUS_
- #include "TempFocus.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- // -- Macintosh Includes --
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // -- OpenDoc Utilites --
-
- #ifndef _DLOGUTIL_
- #include "DlogUtil.h"
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _STORUTIL_
- #include "StorUtil.h"
- #endif
-
- #ifndef _TEMPITER_
- #include "TempIter.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- //==============================================================================
- #pragma mark • Utility functions •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ClipString
- //------------------------------------------------------------------------------
-
- static void ClipString( StringPtr string )
- {
- if ( string[0] == 255 )
- ClipStringToBytes(string, string[0], gGlobals->fEditorsScript);
- }
-
- //------------------------------------------------------------------------------
- // ExactlyEqualStrings
- //------------------------------------------------------------------------------
-
- static ODBoolean ExactlyEqualStrings( StringPtr a, StringPtr b )
- {
- if (a[0] != b[0])
- return kODFalse;
-
- for (int i = 1; i <= a[0]; i++)
- {
- if ( a[i] != b[i] )
- return kODFalse;
- }
-
- return kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // GetFlavorFromSU
- //------------------------------------------------------------------------------
-
- static void GetFlavorFromSU( Environment* ev,
- ODStorageUnit* su,
- HFSFlavor* flavor )
- {
- const ODSize kMinHFSFlavorSize = 2 * sizeof(OSType) + sizeof(unsigned short)
- + sizeof(short) + sizeof(long) + sizeof(char);
-
- if ( ODSUExistsThenFocus(ev, su, kODPropContents,
- gGlobals->fAppleHFSFlavorValueType) )
- {
- ODSize size = su->GetSize(ev);
-
- if ( size < kMinHFSFlavorSize || size > sizeof(HFSFlavor) )
- THROW_M(kODErrInvalidValueType, "HFSFlavor value wasn't of appropriate size to be valid.");
-
- StorageUnitGetValue(su, ev, size, flavor);
- }
- else
- {
- THROW(kODErrInvalidValueType);
- }
- }
-
- //------------------------------------------------------------------------------
- // GetCappuccinoKindProp
- //------------------------------------------------------------------------------
-
- static StringPtr GetCappuccinoKindProp( Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop,
- ODValueType val )
- {
- StringPtr string = kODNULL;
-
- if ( ODSUExistsThenFocus(ev, su, prop, val) )
- {
- ODULong size = su->GetSize(ev);
-
- if ( size == 0 )
- {
- string = (StringPtr) ODNewPtrClear(1);
- }
- else
- {
- su->SetOffset(ev, 0);
-
- if ( size > 255 )
- size = 255;
-
- string = (StringPtr) ODNewPtr(size);
- string[0] = size;
-
- TRY
- StorageUnitGetValue(su, ev, size, string);
- CATCH_ALL
- ODDisposePtr(string);
- RERAISE;
- ENDTRY
-
- // Clip the string after having read it in case it was longer than 255
- // characters. This is to attempt to adjust it for double-byte scripts,
- // but might not fully work correctly.
- ClipString(string);
- }
- }
-
- return string;
- }
-
- //------------------------------------------------------------------------------
- // SetCappuccinoKindProp
- //------------------------------------------------------------------------------
-
- static void SetCappuccinoKindProp( Environment* ev,
- ODStorageUnit* su,
- ODPropertyName prop,
- ODValueType val,
- StringPtr string )
- {
- ODSUForceFocus(ev, su, prop, val);
-
- ODULong oldsize = su->GetSize(ev);
- ODULong newsize = string[0] + 1;
-
- StorageUnitSetValue(su, ev, newsize, string);
-
- if ( oldsize > newsize )
- su->DeleteValue(ev, oldsize - newsize);
- }
-
- //==============================================================================
- // CCappuccinoContent
- //==============================================================================
- #pragma mark -
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- CCappuccinoContent::CCappuccinoContent(Cappuccino* part)
- {
- fPart = part;
- fString = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: CCappuccinoContent
- //
- // Notes: It must be safe to call this routine even if none of the Init
- // methods have been called (or if the Init methods fail).
- //------------------------------------------------------------------------------
-
- CCappuccinoContent::~CCappuccinoContent()
- {
- ODDisposePtr(fString);
- }
-
- //==============================================================================
- #pragma mark • I/O •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: InitCappuccinoContent ()
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InitCappuccinoContent( Environment* ev )
- {
- fString = (StringPtr) ODNewPtrClear(1);
- }
-
- //------------------------------------------------------------------------------
- // Method: InitCappuccinoContent (StringPtr)
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InitCappuccinoContent( Environment* ev,
- StringPtr string )
- {
- fString = (StringPtr) ODNewPtr(string[0] + 1);
- ODBlockMove(string, fString, string[0] + 1);
- }
-
- //------------------------------------------------------------------------------
- // Method: InitCappuccinoContent (ODStorageUnit)
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InitCappuccinoContent( Environment* ev,
- ODStorageUnit* su )
- {
- ODValueType kindToUse = this->GetKindToInternalize(ev, su);
-
- if ( ODISOStrEqual(kindToUse, kCappuccinoKind) )
- {
- this->InternalizeCappuccinoKind(ev, su);
- }
- #ifndef qSingleKindSupported
- else if ( ODISOStrEqual(kindToUse, gGlobals->fTextDataValueType) )
- {
- this->InternalizeTextData(ev, su);
- }
- else if ( HasValidFile(ev, su) )
- {
- this->InternalizeTextFile(ev, su);
- }
- #endif
- else
- {
- this->InternalizeTranslatedData(ev, su);
- }
- }
-
- //------------------------------------------------------------------------------
- // Method: InitByTranslating
- // Origin: CCappuccinoContent
- //
- // Description: This method is called when handling the Paste As dialog box in
- // order to take data from and to given formats and create a new
- // content object that fits that translation. It is also called
- // by the content object to do the actual translation of data.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InitByTranslating( Environment* ev,
- ODStorageUnit* su,
- ODValueType from,
- ODValueType to )
- {
- WASSERT(CCappuccinoContent::IsKindSupported(ev, to));
-
- ODSession* session = ODGetSession(ev, su);
-
- // Create the "from" storage unit view.
- su->Focus(ev, kODPropContents, kODPosUndefined, from, 0, kODPosUndefined);
- TempODStorageUnitView fromView = su->CreateView(ev);
-
- // Create the "to" storage unit view.
- TempODHandle cntrHandle = kODNULL;
- TempODContainer container = kODNULL;
- TempODDocument document = kODNULL;
- TempODDraft toDraft = kODNULL;
-
- ODDraft* partDraft = ODGetDraft(ev, fPart->GetODPart());
-
- if ( partDraft->GetPermissions(ev) >= kODDPSharedWrite )
- {
- partDraft->Acquire(ev);
- toDraft = partDraft;
- }
- else
- {
- // In the case where we don't have write access to our draft, we
- // create a new in-memory container to translate the data into.
- // Creating an in-memory container is a potentially expensive
- // operation, so it might be better to use an in-memory translation
- // via Translate(), but our Content object is only set up to read data
- // from storage units, so this doesn't work for us right now.
-
- cntrHandle = ODNewHandle(0);
- container = CreateMemoryContainer(ev, session, cntrHandle,
- kODDefaultMemoryContainer);
- document = container->AcquireDocument(ev, kODDefaultDocument);
- toDraft = document->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- }
-
- TempODStorageUnit toSU = toDraft->CreateStorageUnit(ev);
-
- TRY
- ODSUForceFocus(ev, toSU, kODPropContents, to);
- TempODStorageUnitView toView = toSU->CreateView(ev);
-
- // Get the translation object and perform the translation.
- ODTranslation* translation = session->GetTranslation(ev);
- ODTranslateResult translateResult = translation->TranslateView(ev, fromView, toView);
-
- // Call InitCappuccinoContent (recursively) to read from this. Note that
- // this should not cause this routine to get called again, as there is now
- // a value type that the content supports, so translation will not be needed
- // in this second call. Also, if for some reason TranslateView returns
- // kODCannotTranslate, we just punt and call InitCappuccinoContent to set us
- // up to be empty.
- if ( translateResult != kODCannotTranslate )
- this->InitCappuccinoContent(ev, toSU);
- else
- this->InitCappuccinoContent(ev);
- CATCH_ALL
- // Remove our temporary storage unit.
- toSU->Focus(ev, kODNULL, kODPosAll, kODTypeAll, 0, kODPosUndefined);
- toSU->Remove(ev);
- RERAISE;
- ENDTRY
-
- // Remove our temporary storage unit.
- toSU->Focus(ev, kODNULL, kODPosAll, kODTypeAll, 0, kODPosUndefined);
- toSU->Remove(ev);
-
- /* if ( pasteAsResult.translateKind != kODNULL )
- {
- // Translation was requested from translateKind to selectedKind
-
- // Create the from storage unit view.
- contentSU->Focus(ev, kODPropContents, kODPosUndefined, pasteAsResult.translateKind,
- 0, kODPosUndefined);
- TempODStorageUnitView fromView = contentSU->CreateView(ev);
-
- // If there's a content property at the destination, we need to remove
- // it because otherwise TranslateView might leave it with stale data.
- if ( ODSUExistsThenFocus(ev, storageUnit, kODPropContents, kODNULL) )
- storageUnit->Remove(ev);
-
- // Add selectedKind and create the to storage unit view
- ODSUForceFocus(ev, storageUnit, kODPropContents, pasteAsResult.selectedKind);
- TempODStorageUnitView toView = storageUnit->CreateView(ev);
-
- // Get the translation object and perform the translation.
- ODTranslation* translation = fSession->GetTranslation(ev);
- ODTranslateResult translateResult = translation->TranslateView(ev, fromView, toView);
-
- // Check for sucessful translation.
- if ( translateResult != kODCannotTranslate )
- {
- // Create an action to paste the new content.
- content->InitCappuccinoContent(ev, storageUnit);
- }
- }
- else
- {
- content->InitCappuccinoContent(ev, contentSU);
- }
-
- if ( content != kODNULL )
- {
- // Create an action to paste the new content.
- CPasteAction* action = new CPasteAction(this, content);
- action->Perform(ev);
- }
- */
- }
-
- //------------------------------------------------------------------------------
- // Method: Prepare
- // Origin: CCappuccinoContent
- //
- // Description: This method will clean out the content property of the given
- // storage unit so that there are no extraneous kinds that we
- // don't support. Also, it must make sure that the ones that are
- // left are in the correct order. This is actually a pretty
- // tricky thing to do for the general case, so this routine is
- // written to work directly on the supported preferred kinds.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::Prepare( Environment* ev,
- ODStorageUnit* su,
- ODValueType preferredKind )
- {
- #ifndef qSingleKindSupported
- WASSERT(preferredKind == kODNULL || this->IsKindSupported(ev, preferredKind));
-
- su->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll);
- ODULong numValues = su->CountValues(ev);
-
- ODBoolean hasReadCappuccinoKind = kODFalse;
-
- for ( ODULong index = numValues; index >= 1; index-- )
- {
- // Index from 1 to n through the values.
- su->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType value = su->GetType(ev);
-
- ODBoolean removeValue = kODTrue;
-
- if ( preferredKind == kODNULL || ODISOStrEqual(preferredKind, kCappuccinoKind) )
- {
- // We shouldn't remove the CappuccinoKind value if it's there.
- // Also, we should only have one in the content property.
- if ( !hasReadCappuccinoKind && ODISOStrEqual(value, kCappuccinoKind) )
- {
- removeValue = kODFalse;
- hasReadCappuccinoKind = kODTrue;
- }
-
- // The CappuccinoKind has to be included before the text kind.
- // If it has been included yet, we'll have to delete the text
- // kind value.
- if ( hasReadCappuccinoKind && ODISOStrEqual(value, gGlobals->fTextDataValueType) )
- removeValue = kODFalse;
- }
- else if ( ODISOStrEqual(preferredKind, gGlobals->fTextDataValueType) )
- {
- if ( ODISOStrEqual(value, gGlobals->fTextDataValueType) )
- removeValue = kODFalse;
- }
-
- if ( removeValue )
- su->Remove(ev);
- }
- #else
- su->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll);
- ODULong numValues = su->CountValues(ev);
-
- for ( ODULong index = numValues; index >= 1; index-- )
- {
- // Index from 1 to n through the values.
- su->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType value = su->GetType(ev);
-
- if ( !ODISOStrEqual(value, kCappuccinoKind) )
- su->Remove(ev);
- }
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: Externalize
- // Origin: CCappuccinoContent
- //
- // Description: This method will write out values based on the preferred kind
- // (assuming the highest fidelity preferred kind if the
- // preferredKind value is null). It should also write out any
- // data interchange values, if possible.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::Externalize( Environment* ev,
- ODStorageUnit* su,
- ODDraftKey key,
- ODValueType preferredKind )
- {
- #ifndef qSingleKindSupported
- WASSERT(preferredKind == kODNULL ||
- this->IsKindSupported(ev, preferredKind));
-
- if ( preferredKind == kODNULL || ODISOStrEqual(preferredKind, kCappuccinoKind) )
- {
- this->ExternalizeCappuccinoKind(ev, su);
- // Externalize a standard data interchange kind.
- this->ExternalizeTextData(ev, su);
- }
- else if ( ODISOStrEqual(preferredKind, gGlobals->fTextDataValueType) )
- {
- this->ExternalizeTextData(ev, su);
- }
- #else
- this->ExternalizeCappuccinoKind(ev, su);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeOneKind
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::ExternalizeOneKind( Environment* ev,
- ODStorageUnit* su,
- ODDraftKey key,
- ODValueType kind )
- {
- #ifndef qSingleKindSupported
- WASSERT(this->IsKindSupported(ev, kind));
-
- if ( ODISOStrEqual(kind, kCappuccinoKind) )
- this->ExternalizeCappuccinoKind(ev, su);
- else if ( ODISOStrEqual(kind, gGlobals->fTextDataValueType) )
- this->ExternalizeTextData(ev, su);
- #else
- WASSERT(ODISOStrEqual(kind, kCappuccinoKind));
- this->ExternalizeCappuccinoKind(ev, su);
- #endif
- }
-
- //==============================================================================
- #pragma mark • Promises •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Promise
- // Origin: CCappuccinoContent
- //
- // Description: This method will write out a data interchange value to the
- // content property when it is called. It should be called when
- // externalizing data for a drag-and-drop, cut, or copy operation.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::Promise( Environment* ev,
- ODStorageUnit* su,
- ODDraftKey key,
- ODBoolean isForClipboard,
- Cappuccino* part )
- {
- CCappuccinoContentPromise* nativePromise
- = new CCappuccinoContentPromise(part, this, kCappuccinoKind);
-
- #ifndef qSingleKindSupported
- CCappuccinoContentPromise* interchangePromise
- = new CCappuccinoContentPromise(part, this, gGlobals->fTextDataValueType);
- #endif
-
- nativePromise->PromiseTo(ev, su);
- interchangePromise->PromiseTo(ev, su);
-
- // Add our promises to the appropriate promise set.
- CPromiseSet* set = isForClipboard ? gGlobals->fClipboardPromises
- : gGlobals->fDragPromises;
- set->Clear(ev);
- set->Add(ev, nativePromise);
- #ifndef qSingleKindSupported
- set->Add(ev, interchangePromise);
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: Fulfill
- // Origin: CCappuccinoContent
- //
- // Description: This method will fulfill a promise made to a storage unit by
- // an instance of this content object.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::Fulfill( Environment* ev,
- ODStorageUnit* su,
- ODValueType valueType )
- {
- this->ExternalizeOneKind(ev, su, kODNULLKey, valueType);
- }
-
- //==============================================================================
- #pragma mark • Accessors •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: GetString
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- StringPtr CCappuccinoContent::GetString()
- {
- return fString;
- }
-
- //------------------------------------------------------------------------------
- // Method: IsEmpty
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::IsEmpty()
- {
- return (fString[0] == 0);
- }
-
- //==============================================================================
- #pragma mark • Imaging •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: Draw
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::Draw( Environment* ev,
- ODFacet* facet,
- CSettings* settings )
- {
- SOM_Trace("Cappuccino","DrawFrameView");
-
- ASSERT_NOT_NULL(facet);
-
- // If the facet being draw is dependent to a source frame in
- // another window, we need to access the source frame to determine
- // what size to draw the content.
-
- ODFrame* frame = facet->GetFrame(ev);
- CFrameInfo* frameInfo = CFrameInfo::GetFrameInfo(ev, frame);
-
- // Get the facet's canvas so shapes are returned in the correct
- // coordinate system.
- ODCanvas* biasCanvas = facet->GetCanvas(ev);
-
- // Calculate font height for drawing.
- TempODShape frameShape = frame->AcquireFrameShape(ev, biasCanvas);
- ODRgnHandle frameRgn = frameShape->GetQDRegion(ev);
- Rect bounds = (**frameRgn).rgnBBox;
-
- PenState penState;
- GetPenState(&penState);
- PenNormal();
-
- if ( settings->GetDoesDrawFrame() )
- {
- FrameRect(&bounds);
-
- Rect eraseBounds = bounds;
- InsetRect(&eraseBounds, 1, 1);
- EraseRect(&eraseBounds);
- }
- else
- {
- EraseRect(&bounds);
- }
-
- // Save off port chararcteristics so we can restore it later.
- GrafPtr port = facet->GetCanvas(ev)->GetQDPort(ev);
- ODUShort saveSize = port->txSize;
- ODUShort saveFont = port->txFont;
- Style saveFace = port->txFace;
-
- if ( !this->IsEmpty() )
- {
- // Set the font size.
- TextFont(settings->GetTextFont());
- TextSize(settings->GetTextSize());
- TextFace(0);
-
- StringPtr string = this->GetString();
-
- Rect textBounds = bounds;
- if ( settings->GetDoesDrawFrame() )
- InsetRect(&textBounds, 2, 2);
-
- TETextBox(string + 1, string[0], &textBounds, teFlushDefault);
-
- // If the part is selected, fill the background with
- // the highlight color.
- if ( facet->GetHighlight(ev) == kODFullHighlight )
- {
- UInt8 mode = LMGetHiliteMode();
- BitClr(&mode, pHiliteBit);
- LMSetHiliteMode(mode);
- InvertRect(&bounds);
- }
-
- // Restore port chararcteristics.
- port->txSize = saveSize;
- port->txFont = saveFont;
- port->txFace = saveFace;
- }
-
- SetPenState(&penState);
- }
-
- //==============================================================================
- #pragma mark • Protected I/O methods •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: InternalizeCappuccinoKind
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InternalizeCappuccinoKind( Environment* ev,
- ODStorageUnit* su )
- {
- fString = GetCappuccinoKindProp(ev, su, kODPropContents, kCappuccinoKind);
- }
-
- //------------------------------------------------------------------------------
- // Method: InternalizeTextData
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
- #ifndef qSingleKindSupported
-
- void CCappuccinoContent::InternalizeTextData( Environment* ev,
- ODStorageUnit* su )
- {
- if ( !ODSUExistsThenFocus(ev, su, kODPropContents, gGlobals->fTextDataValueType) )
- THROW(kODErrInvalidValueType);
-
- ODULong size = su->GetSize(ev);
-
- // Since we only have a Pascal string, we're limited to 255 characters.
- if (size > 255)
- size = 255;
-
- fString = (StringPtr) ODNewPtrClear(size + 1);
- size = StorageUnitGetValue(su, ev, size, &fString[1]);
- fString[0] = size;
-
- // Clip the string after having read it in case it was longer than 255
- // characters. This is to attempt to adjust it for double-byte scripts,
- // but might not fully work correctly.
- ClipString(fString);
- }
-
- #endif
- //------------------------------------------------------------------------------
- // Method: InternalizeTextFile
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
- #ifndef qSingleKindSupported
-
- void CCappuccinoContent::InternalizeTextFile( Environment* ev,
- ODStorageUnit* su )
- {
- HFSFlavor flavor;
- GetFlavorFromSU(ev, su, &flavor);
-
- WASSERT(flavor.fileType == 'TEXT');
-
- ODSShort fileRefNum;
- THROW_IF_ERROR(FSpOpenDF(&flavor.fileSpec, fsRdPerm, &fileRefNum));
-
- TRY
- ODSLong size;
- THROW_IF_ERROR(GetEOF(fileRefNum, &size));
-
- // Since we only have a Pascal string, we're limited to 255 characters,
- // however, we will crop it to 254 in case we're dealing with a double-
- // byte script.
- if (size > 255)
- size = 255;
-
- fString = (StringPtr) ODNewPtrClear(size + 1);
- fString[0] = size;
-
- // If the file is empty, there's no reason to try to read it.
- if ( size > 0 )
- {
- ODSLong bytesRead = size;
- FSRead(fileRefNum, &bytesRead, &fString[1]);
- }
-
- // Clip the string after having read it in case it was longer than 255
- // characters. This is to attempt to adjust it for double-byte scripts,
- // but might not fully work correctly.
- ClipString(fString);
-
- CATCH_ALL
- FSClose(fileRefNum);
- RERAISE;
- ENDTRY
-
- FSClose(fileRefNum);
- }
-
- #endif
- //------------------------------------------------------------------------------
- // Method: InternalizeTranslatedData
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::InternalizeTranslatedData( Environment* ev,
- ODStorageUnit* su )
- {
- ODSession* session = ODGetSession(ev, su);
-
- // Determine the kinds that we are translating from and to.
- ODValueType from = kODNULL;
- ODValueType to = kODNULL;
- if ( !this->GetTranslateKinds(ev, su, &from, &to) )
- THROW(kODErrInvalidValueType);
-
- TempODValueType fromTemp = from;
- TempODValueType toTemp = to;
-
- this->InitByTranslating(ev, su, from, to);
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeCappuccinoKind
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::ExternalizeCappuccinoKind( Environment* ev,
- ODStorageUnit* su )
- {
- SetCappuccinoKindProp(ev, su, kODPropContents, kCappuccinoKind, fString);
- }
-
- //------------------------------------------------------------------------------
- // Method: ExternalizeTextData
- // Origin: CCappuccinoContent
- //
- // Description: This method will write out a data interchange value to the
- // content property when it is called. It should be called when
- // externalizing data for a drag-and-drop, cut, or copy operation.
- //------------------------------------------------------------------------------
- #ifndef qSingleKindSupported
-
- void CCappuccinoContent::ExternalizeTextData( Environment* ev,
- ODStorageUnit* su )
- {
- ODSUForceFocus(ev, su, kODPropContents, gGlobals->fTextDataValueType);
- ODULong oldSize = su->GetSize(ev);
-
- StorageUnitSetValue(su, ev, fString[0], &fString[1]);
-
- if ( oldSize > fString[0] )
- su->DeleteValue(ev, oldSize - fString[0]);
- }
-
- #endif
- //==============================================================================
- #pragma mark • Static utility functions •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: IsKindSupported [static]
- // Origin: CCappuccinoContent
- //
- // Description: This static method returns a boolean indicating whether the
- // given kind is supported by this part.
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::IsKindSupported( Environment* ev,
- ODValueType kind )
- {
- #ifndef qSingleKindSupported
- return ( ODISOStrEqual(kind, kCappuccinoKind) ||
- ODISOStrEqual(kind, gGlobals->fTextDataValueType) );
- #else
- return ( ODISOStrEqual(kind, kCappuccinoKind) );
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: RecoverKindPtr [static]
- // Origin: CCappuccinoContent
- //
- // Description: Given a pointer to an value type, we will recover a pointer to
- // our constant or global version of the same type. This is used
- // to assure we have a pointer to a permanent string and not one
- // that might be deleted by some other object.
- //------------------------------------------------------------------------------
-
- ODValueType CCappuccinoContent::RecoverKindPtr( Environment* ev,
- ODValueType kind )
- {
- #ifndef qSingleKindSupported
- WASSERT(CCappuccinoContent::IsKindSupported(ev, kind));
-
- if ( ODISOStrEqual(kind, kCappuccinoKind) )
- return kCappuccinoKind;
- else if ( ODISOStrEqual(kind, gGlobals->fTextDataValueType) )
- return gGlobals->fTextDataValueType;
- else
- return kODNULL;
- #else
- return kCappuccinoKind;
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Function: GetNextHighestFidelity [static]
- //
- // Description: Returns the type token that is of the next highest fidelity
- // of the kinds we support.
- //
- // If kODNULL is passed in, this returns the highest fidelity.
- //
- // If the lowest fidelity is passed in, this returns kODNULL.
- //------------------------------------------------------------------------------
-
- ODValueType CCappuccinoContent::GetNextHighestFidelity( ODValueType currentKind )
- {
- #ifndef qSingleKindSupported
- ODValueType nextKind;
-
- if ( currentKind == kODNULL )
- nextKind = kCappuccinoKind;
-
- else if ( ODISOStrEqual(currentKind, kCappuccinoKind) )
- nextKind = gGlobals->fTextDataValueType;
-
- else if ( ODISOStrEqual(currentKind, gGlobals->fTextDataValueType) )
- nextKind = kODNULL;
-
- else
- // It's something we don't support, so start at the top.
- nextKind = kCappuccinoKind;
-
- return nextKind;
- #else
- ODValueType nextKind;
-
- if ( currentKind == kODNULL )
- nextKind = kCappuccinoKind;
- else
- nextKind = kODNULL;
-
- return nextKind;
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Function: GetKindToInternalize [static]
- // Origin: CCappuccinoContent
- //
- // Description: Returns a value representing the kind of data that should be
- // internalized from the given storage unit based on the kinds
- // that are supported and the preferred kind of the data.
- //------------------------------------------------------------------------------
-
- ODValueType CCappuccinoContent::GetKindToInternalize( Environment* ev,
- ODStorageUnit* su )
- {
- // This should represent the kind of data that should be internalized
- // from the given storage unit.
- ODValueType kindToUse = kODNULL;
-
- TempODValueType docPrefKind = ODGetISOStrProp(ev, su, kODPropPreferredKind,
- kODISOStr, kODNULL, kODNULL);
-
- // If the data has a preferred kind, see if we can use it.
- if ( docPrefKind != kODNULL
- && CCappuccinoContent::IsKindSupported(ev, docPrefKind)
- && su->Exists(ev, kODPropContents, docPrefKind, 0) )
- {
- kindToUse = CCappuccinoContent::RecoverKindPtr(ev, docPrefKind);
- }
-
- // If there is not a part-preferred kind, we don't support it, or it
- // wasn't found, find the first value (the one with highest fidelity)
- // that we understand.
- if ( kindToUse == kODNULL )
- kindToUse = CCappuccinoContent::GetHighestFidelityKindSupported(ev, su);
-
- return kindToUse;
- }
-
- //------------------------------------------------------------------------------
- // Method: GetHighestFidelityKindSupported [static]
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- ODValueType CCappuccinoContent::GetHighestFidelityKindSupported( Environment* ev,
- ODStorageUnit* su )
- {
- #ifndef qSingleKindSupported
- ODBoolean hasSupportedKind = kODFalse;
-
- for ( ODValueType kindToLookFor = CCappuccinoContent::GetNextHighestFidelity();
- kindToLookFor != kODNullTypeToken;
- kindToLookFor = CCappuccinoContent::GetNextHighestFidelity(kindToLookFor) )
- {
- // Note: we have to focus here (not just Exists()), or (for some reason)
- // importing doesn't work correctly. Instead, a translation dialog
- // comes up and the drag (if that's what it is) is refused.
- if ( ODSUExistsThenFocus(ev, su, kODPropContents, kindToLookFor) )
- {
- return kindToLookFor;
- }
- }
-
- return kODNULL;
- #else
- if ( ODSUExistsThenFocus(ev, su, kODPropContents, kCappuccinoKind) )
- return kCappuccinoKind;
- else
- return kODNULL;
- #endif
- }
-
- //------------------------------------------------------------------------------
- // Method: HasSupportedKind [static]
- // Origin: CCappuccinoContent
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::HasSupportedKind( Environment* ev,
- ODStorageUnit* su )
- {
- return (CCappuccinoContent::GetHighestFidelityKindSupported(ev, su) != kODNULL);
- }
-
- //------------------------------------------------------------------------------
- // Method: HasValidContent [static]
- // Origin: CCappuccinoContent
- //
- // Description: This method is called to determine if a storage unit contains
- // any data that we understand or can translate.
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::HasValidContent( Environment* ev,
- ODStorageUnit* su,
- ODBoolean* requiresTranslation )
- {
- SOM_Trace("CCappuccinoContent","HasValidContent");
-
- if ( requiresTranslation != kODNULL )
- *requiresTranslation = kODFalse;
-
- // Look for a type we support first to save time.
- if ( CCappuccinoContent::HasSupportedKind(ev, su) )
- {
- return kODTrue;
- }
- else if ( HasValidFile(ev, su) )
- {
- return kODTrue;
- }
- else if ( CCappuccinoContent::CanTranslate(ev, su) )
- {
- if ( requiresTranslation != kODNULL )
- *requiresTranslation = kODTrue;
-
- return kODTrue;
- }
-
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // Method: HasValidFile [static]
- // Origin: CCappuccinoContent
- //
- // Description: This method is called to determine if a storage unit contains
- // an HFSFlavor indicating a file that we can read and internalize.
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::HasValidFile( Environment* ev,
- ODStorageUnit* su )
- {
- ODBoolean hasValidFile = kODFalse;
-
- #ifndef qSingleKindSupported
- if ( ODSUExistsThenFocus(ev, su, kODPropContents,
- gGlobals->fAppleHFSFlavorValueType) )
- {
- HFSFlavor flavor;
- GetFlavorFromSU(ev, su, &flavor);
-
- // We understand a plain TEXT file for compatability with other apps.
- // Note: This must be the last value that is checked for because it will
- // exist if an OpenDoc file with one of the other values was dropped in.
- if ( flavor.fileType == 'TEXT' )
- hasValidFile = kODTrue;
- }
- #endif
-
- return hasValidFile;
- }
-
- //------------------------------------------------------------------------------
- // Method: CanTranslate [static]
- // Origin: CCappuccinoContent
- //
- // Description: This method is called to determine if a storage unit contains
- // any content that can be translated into a format this part
- // understands.
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::CanTranslate( Environment* ev,
- ODStorageUnit* su )
- {
- return GetTranslateKinds(ev, su);
- }
-
- //------------------------------------------------------------------------------
- // Method: GetTranslateKinds [static]
- // Origin: CCappuccinoContent
- //
- // Description: This method is called to get the first kind of content that a
- // storage unit contains that can be translated into a kind this
- // part supports. It also returns the kind it can be understood
- // as.
- //------------------------------------------------------------------------------
-
- ODBoolean CCappuccinoContent::GetTranslateKinds( Environment* ev,
- ODStorageUnit* su,
- ODValueType* from,
- ODValueType* to )
- {
- ODBoolean found = kODFalse;
-
- *from = kODNULL;
- *to = kODNULL;
-
- // Check for the possibility of translation.
- ODTranslation* translation = ODGetSession(ev, su)->GetTranslation(ev);
-
- // Get the number of values in the contents property.
- su->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll);
- ODULong numValues = su->CountValues(ev);
-
- // Iterate from 1 to n through the values in the contents property.
- for ( ODULong index = 1 ; index <= numValues && !found ; index++ )
- {
- su->Focus(ev, kODPropContents, kODPosUndefined,
- kODNULL, index, kODPosUndefined);
-
- // Get the ISO type name for the value. The temp object
- // will automatically delete the returned value when this
- // scope is exited.
- TempODValueType foreignDataType = su->GetType(ev);
-
- // Check that if there is a translator that recognizes the "foreign" data
- // type, that it can translate to a data type we understand.
- if ( translation->CanTranslate(ev, foreignDataType) == kODCanTranslate )
- {
- TempODTypeList validTypes = translation->GetTranslationOf(ev, foreignDataType);
-
- for ( TempODTypeListIterator type(ev, validTypes) ;
- type.IsNotComplete() && !found ; type.Next() )
- {
- if ( CCappuccinoContent::IsKindSupported(ev, type) )
- {
- if ( from != kODNULL )
- *from = foreignDataType.DontDelete();
- if ( to != kODNULL )
- *to = DuplicateISOStr(type);
-
- found = kODTrue;
- break;
- }
- }
- }
- }
-
- return found;
- }
-
- //------------------------------------------------------------------------------
- // Method: DoSetTextDialog [static]
- // Origin: CCappuccinoContent
- //
- // Description: The method is called by the part when the user chooses the
- // Set Text menu item.
- //------------------------------------------------------------------------------
-
- void CCappuccinoContent::DoSetTextDialog( Environment* ev,
- ODFrame* frame,
- Cappuccino* part,
- CCappuccinoContent* currentContent )
- {
- #ifndef qViewerBuild
- ASSERT_NOT_NULL(frame);
- ASSERT_NOT_NULL(currentContent);
-
- if ( !part->TryToEdit(ev, frame) )
- return;
-
- const ODUShort kTextField = 3;
-
- // We must request the Modal focus to prevent multiple modal dialogs being
- // displayed simultaneously.
-
- TempFocus modalFocus(ev, gGlobals->fModalFocus, frame);
- if ( modalFocus.Request() )
- {
- CTempDialogState dialogState(ev, ODGetSession(ev, part->GetODPart()));
- DialogPtr dialog = dialogState.CreateDialog(kSetTextDialogID);
-
- short iType;
- Handle iHandle;
- Rect iRect;
-
- // Set dialog font and other std things.
- SetDialogDefaults(dialog, kDialogFontInfoID, kSettingsFontIndex);
-
- // Get a string representation of the font size and put it in the text field.
- GetDialogItem(dialog, kTextField, &iType, &iHandle, &iRect);
- SetDialogItemText(iHandle, currentContent->GetString());
- SelectDialogItemText(dialog, kTextField, 0, 32767);
-
- // Show the window and handle events in it.
- ShowWindow(dialog);
-
- ODSShort itemHit;
- do
- {
- ModalDialog(GetODDialogFilter(), &itemHit);
- }
- while (itemHit != ok && itemHit != cancel);
-
- // If OK was hit, handle the change.
- if ( itemHit == ok )
- {
- // Get the new text.
- Str255 str;
- GetDialogItem(dialog, kTextField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, str);
-
- CCappuccinoContent* content = new CCappuccinoContent(part);
- TempRefCounted contentTemp = content;
- content->InitCappuccinoContent(ev, str);
-
- if ( *currentContent != *content )
- {
- CSetTextAction* action = new CSetTextAction(part, content);
- action->Perform(ev);
- }
- }
- }
- #endif
- }
-
- //==============================================================================
- #pragma mark • Operators •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: operator == (CSettings&, CSettings&)
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- ODBoolean operator == (const CCappuccinoContent& a, const CCappuccinoContent& b)
- {
- return ExactlyEqualStrings(a.fString, b.fString);
- }
-
- //------------------------------------------------------------------------------
- // Method: operator != (CSettings&, CSettings&)
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- ODBoolean operator != (const CCappuccinoContent& a, const CCappuccinoContent& b)
- {
- return !(a == b);
- }
-
- //==============================================================================
- // CSettings
- //==============================================================================
- #pragma mark -
-
- //------------------------------------------------------------------------------
- // Method: Constructor
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- CSettings::CSettings(Cappuccino* part)
- {
- fPart = part;
- fTextFont = systemFont;
- fTextSize = 0;
- fDrawFrame = kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Method: Destructor
- // Origin: CSettings
- //
- // Notes: It must be safe to call this routine even if none of the Init
- // methods have been called (or if the Init methods fail).
- //------------------------------------------------------------------------------
-
- CSettings::~CSettings()
- {
- }
-
- //------------------------------------------------------------------------------
- // Method: UseDefaults
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- void CSettings::UseDefaults()
- {
- long result = GetScriptVariable(gGlobals->fEditorsScript,
- smScriptAppFondSize);
- fTextFont = HiWord(result);
- fTextSize = LoWord(result);
-
- fDrawFrame = kODTrue;
- }
-
- //==============================================================================
- #pragma mark • I/O •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: InitSettings
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- void CSettings::InitSettings(Environment* ev)
- {
- this->UseDefaults();
- }
-
- //------------------------------------------------------------------------------
- // Method: InitSettings
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- void CSettings::InitSettings(Environment* ev, ODStorageUnit* su)
- {
- this->UseDefaults();
-
- // Get the size from the font size annotation.
- if ( su->Exists(ev, kTextSizeAnnotation, kODUShort, 0) )
- fTextSize = ODGetUShortProp(ev, su, kTextSizeAnnotation, kODUShort);
-
- // Get the font from the font size annotation.
- TempODIText intlFontName = kODNULL;
- if ( su->Exists(ev, kTextFontAnnotation, kODMacIText, 0) )
- {
- intlFontName = ODGetITextProp(ev, su, kTextFontAnnotation, kODMacIText, kODNULL);
- if ( intlFontName != kODNULL && GetITextStringLength(intlFontName) != 0 )
- {
- Str255 fontName;
- (void) GetITextPString(intlFontName, fontName);
- GetFNum(fontName, &fTextFont);
- }
- }
-
- if ( su->Exists(ev, kDrawFrameAnnotation, kODBoolean, 0) )
- fDrawFrame = ODGetBooleanProp(ev, su, kDrawFrameAnnotation, kODBoolean);
- }
-
- //------------------------------------------------------------------------------
- // Method: Externalize
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- void CSettings::Externalize(Environment* ev, ODStorageUnit* su)
- {
- Str255 fontName;
- GetFontName(fTextFont, fontName);
- TempODIText intlFontName = CreateITextPString(smRoman, langEnglish, fontName);
-
- ODSetITextProp(ev, su, kTextFontAnnotation, kODMacIText, intlFontName);
- ODSetUShortProp(ev, su, kTextSizeAnnotation, kODUShort, fTextSize);
- ODSetBooleanProp(ev, su, kDrawFrameAnnotation, kODBoolean, fDrawFrame);
- }
-
- //==============================================================================
- #pragma mark • Settings •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: DoSettingsDialog [static]
- // Origin: CSettings
- //
- // Description: The method is called by the part when the user chooses the
- // Settings menu item or clicks the Settings button in Part Info.
- //------------------------------------------------------------------------------
-
- void CSettings::DoSettingsDialog( Environment* ev,
- ODFrame* frame,
- Cappuccino* part,
- CSettings* currentSettings )
- {
- #ifndef qViewerBuild
- ASSERT_NOT_NULL(currentSettings);
- ASSERT_NOT_NULL(frame);
-
- if ( !part->TryToEdit(ev, frame) )
- return;
-
- const ODUShort kFontPopup = 7;
- const ODUShort kSizeField = 8;
- const ODUShort kDrawFrameCheckbox = 9;
-
- // We must request the Modal focus to prevent multiple modal dialogs being
- // displayed simultaneously.
-
- TempFocus modalFocus(ev, gGlobals->fModalFocus, frame);
- if ( modalFocus.Request() )
- {
- CTempDialogState dialogState(ev, ODGetSession(ev, part->GetODPart()));
- DialogPtr dialog = dialogState.CreateDialog(kSettingsDialogID);
-
- short iType;
- Handle iHandle;
- Rect iRect;
- Str255 strValue;
-
- // Set dialog font and other std things.
- SetDialogDefaults(dialog, kDialogFontInfoID, kSettingsFontIndex);
-
- // Get a string representation of the font size and put it in the text field.
- NumToString(currentSettings->fTextSize, strValue);
-
- GetDialogItem(dialog, kSizeField, &iType, &iHandle, &iRect);
- SetDialogItemText(iHandle, strValue);
- SelectDialogItemText(dialog, kSizeField, 0, 32767);
-
- // Get the popup menu control.
- ControlHandle popupMenu;
- GetDialogItem(dialog, kFontPopup, &iType, (Handle*) &popupMenu, &iRect);
-
- // Find the initial item for the popup menu and set it.
- {
- Str255 fontStr;
- GetFontName(currentSettings->fTextFont, fontStr);
-
- PopupPrivateData** privData = (PopupPrivateData**) (**popupMenu).contrlData;
- MenuHandle privMenu = (**privData).mHandle;
-
- short initialItem = 0;
- for (int i = 1; i <= CountMItems(privMenu); i++)
- {
- Str255 menuItem;
- GetMenuItemText(privMenu, i, menuItem);
-
- if ( IUEqualString(fontStr, menuItem) == 0 )
- {
- initialItem = i;
- break;
- }
- }
-
- SetControlValue(popupMenu, initialItem);
- }
-
- // Set initial state of checkboxes.
- {
- ControlHandle checkboxH;
- GetDialogItem(dialog, kDrawFrameCheckbox, &iType, (Handle*) &checkboxH, &iRect);
-
- SetControlValue(checkboxH, (short) currentSettings->fDrawFrame);
- }
-
- // Show the window and handle events in it.
- ShowWindow(dialog);
- ModalFilterUPP otherDialogProc = NewModalFilterProc(IntegerDialogFilter);
-
- ODSShort itemHit;
- do
- {
- ModalDialog(otherDialogProc, &itemHit);
-
- GetDialogItem(dialog, itemHit, &iType, &iHandle, &iRect);
-
- switch ( itemHit )
- {
- case kDrawFrameCheckbox:
- SetControlValue((ControlHandle) iHandle,
- !GetControlValue((ControlHandle) iHandle));
- break;
- }
- }
- while (itemHit != ok && itemHit != cancel);
-
- DisposeRoutineDescriptor(otherDialogProc);
-
- // If OK was hit, handle the change.
- if ( itemHit == ok )
- {
- CSettings* newSettings = new CSettings(part);
- TempRefCounted newSettingsTemp = newSettings;
-
- // -- Get the font name --
- short controlValue = GetControlValue(popupMenu);
- PopupPrivateData** privData = (PopupPrivateData**) (**popupMenu).contrlData;
- MenuHandle privMenu = (**privData).mHandle;
-
- Str255 fontStr;
- GetMenuItemText(privMenu, controlValue, fontStr);
-
- short newFontNum;
- GetFNum(fontStr, &newFontNum);
- newSettings->fTextFont = newFontNum;
-
- // -- Get the font size --
- GetDialogItem(dialog, kSizeField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, strValue);
-
- // Get the default size in case the text field is empty.
- long newSize = LoWord(GetScriptVariable(gGlobals->fEditorsScript, smScriptAppFondSize));
-
- // If the string isn't empty, turn it into a number.
- if ( strValue[0] > 0 )
- StringToNum(strValue, &newSize);
-
- // Limit the font size to 512 point (pretty big...).
- if ( newSize > 512 )
- newSize = 512;
-
- newSettings->fTextSize = (ODUShort) newSize;
-
- // -- Get the 'draw frame' checkbox --
- {
- ControlHandle checkboxH;
- GetDialogItem(dialog, kDrawFrameCheckbox, &iType, (Handle*) &checkboxH, &iRect);
-
- newSettings->fDrawFrame = (ODBoolean) GetControlValue(checkboxH);
- }
-
- // -- Propogate the change --
- if ( *newSettings != *currentSettings )
- {
- CSettingsChangeAction* action = new CSettingsChangeAction(part,
- newSettings);
- action->Perform(ev);
- }
- }
- }
- #endif
- }
-
- //==============================================================================
- #pragma mark • Operators •
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: operator == (CSettings&, CSettings&)
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- ODBoolean operator == (const CSettings& a, const CSettings& b)
- {
- return ( a.fTextFont == b.fTextFont
- && a.fTextSize == b.fTextSize
- && a.fDrawFrame == b.fDrawFrame );
- }
-
- //------------------------------------------------------------------------------
- // Method: operator != (CSettings&, CSettings&)
- // Origin: CSettings
- //------------------------------------------------------------------------------
-
- ODBoolean operator != (const CSettings& a, const CSettings& b)
- {
- return !(a == b);
- }
-
-